<?php

session_start();
if (isset($_POST['submit'])) {
    $product_id = $_POST['product_id'];
    if (!isset($_SESSION['cart'])) {
        $_SESSION['cart'] = serialize(array($product_id => array('id' => $product_id, 'soluong' => $_POST['order_quantity'])));
    } else {
        $arr = unserialize($_SESSION['cart']);
        $arr[$product_id] = array('id' => $product_id, 'soluong' => $_POST['order_quantity']);
        $_SESSION['cart'] = serialize($arr);
    }
    header('Location: index.php');
}

if ($_GET['action'] == 'del') {
    $arr = unserialize($_SESSION['cart']);
    if (isset($_GET['product_id'])) {
        $product_id = $_GET['product_id'];
        unset($arr[$product_id]);
        $_SESSION['cart'] = serialize($arr);
    }
    header('Location:index.php');
}
?>
